/*
 * @Author: AHANG
 * @Date: 2022-06-16 11:15:52
 * @LastEditors: AHANG
 * @LastEditTime: 2022-07-21 15:20:43
 * @Description:  axios 封装
 */

import axios from "axios";
import Vue from "vue";

//1利用axios对象方法create()创建一个axios实例
// eslint-disable-next-line no-unused-vars
const requests = axios.create({
  //   baseURL: "/api", //基础路径//请求的基础路径
  timeout: 5000,
  headers: {
    "Content-Type": "application/json",
    "X-Custom-Header": "foobar",
  },
});
//请求拦截器
requests.interceptors.request.use(
  (config) => {
    //在请求发出之前进行一些操作
    //token
    // if (localStorage.getItem("token")) {
    //   config.headers.Authorization = localStorage.getItem("token");
    // }
    // const token = localStorage.getItem("token");
    // config.headers.Authorization = localStorage.getItem("token");
    // console.log(config);
    // Vue.$store.commit("global/SET_DIALOG_TIME");
    return config;
  },
  (error) => {
    //请求错误时做一些处理
    return Promise.reject(error);
  }
);
//响应拦截器
requests.interceptors.response.use(
  (response) => {
    //对响应数据做一些处理
    console.log(response);
    return response;
  },
  (error) => {
    //请求错误时做一些处理
    return Promise.reject(error);
  }
);
//暴露接口
export default axios;
